#include <kernel.h>

extern dde_kit_addr_t *inv_map;

int
LD_SYM(dde_kit_request_mem)(dde_kit_addr_t start, dde_kit_size_t size,
					 int wc, dde_kit_addr_t *vaddr)
{
	 uint32_t offset = start & (DDE_KIT_PAGE_SIZE - 1);
	 start -= offset;
	 size  += offset;

	 void *res = ekf_valloc(size);
	 if (res == NULL)
		  return -1;

	 LD_SYM(dde_kit_pgtab_set_region_with_size)((void *)res, start, size);
	 *vaddr = (dde_kit_addr_t)res + offset;

	 return 0;
}

int
LD_SYM(dde_kit_release_mem)(dde_kit_addr_t start, dde_kit_size_t size)
{
	 uint32_t offset = start & (DDE_KIT_PAGE_SIZE - 1);
	 start -= offset;
	 size  += offset;

	 LD_SYM(dde_kit_pgtab_clear_region)((void *)inv_map[(start >> DDE_KIT_PAGE_SHIFT)]);
	 ekf_vfree((void *)inv_map[(start >> DDE_KIT_PAGE_SHIFT)]);

	 return 0;
}

#if DK_EXPORT_SYM

void
dde_kit_resources_symbol(void)
{
	 elf_mod_export_symbol("dde_kit_request_mem", &dde_kit_request_mem, 1);
	 elf_mod_export_symbol("dde_kit_release_mem", &dde_kit_release_mem, 1);
}

#endif
